package com.ym.b2b.user.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.commons.dao.BaseDao;
import com.ym.b2b.user.dao.EmCUserDAO;
import com.ym.b2b.user.sqlbean.EmCUser;
import com.zc.commons.base.Page;

@Repository
public class EmCUserDAOImpl<T> extends BaseDao<T> implements EmCUserDAO {

    @Override
    public Long searchPageEmCUserNum(EmCUser emcuser) throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emcuser);
        return (Long) listNum("EM_C_USER.searchPageEmCUserNum", map);
    }

    @Override
    public Page<?> searchPageEmCUser(EmCUser emcuser, Page<EmCUser> page) throws DataAccessException {
        page.setTotalRow(searchPageEmCUserNum(emcuser));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emcuser);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_C_USER.searchPageEmCUser", map));
        return page;
    }

    @Override
    public void insertEmCUser(EmCUser record) throws DataAccessException {
        sqlMapClient.insert("EM_C_USER.insertEmCUser", record);
    }

    @Override
    public int updateEmCUser(EmCUser record) throws DataAccessException {
        int rows = update("EM_C_USER.updateEmCUser", record);
        return rows;
    }

    @Override
    public void updateEmCUserBat(EmCUser record) {
        // TODO Auto-generated method stub
        EmCUser emCuser = new EmCUser();
        emCuser.setIsValid(record.getIsValid());
        emCuser.setUserIdList(record.getUserIdList());
        update("EM_C_USER.updateEmCUserBat", emCuser);

    }

    @Override
    public int deleteMultipleEmBNews(String userIdList) {
        int rows = delete("EM_C_USER.deleteMultipleEmCUser", userIdList);
        return rows;
    }

    @Override
    public int deleteEmCUser(Long userId) throws DataAccessException {
        EmCUser key = new EmCUser();
        key.setUserId(userId);
        int rows = delete("EM_C_USER.deleteEmCUser", key);
        return rows;
    }

    @Override
    public EmCUser searchEmCUser(EmCUser emCuser) throws DataAccessException {
        return (EmCUser) find("EM_C_USER.searchEmCUser", emCuser);
    }

    @Override
    public List<EmCUser> searchEmCUserList(EmCUser emCUser) throws DataAccessException {
        // map.put("map", emCUser);
        return list("EM_C_USER.searchEmCUser", emCUser);
    }
}
